class Solution:
    def canPartition(self, nums: list) -> bool:
        sum_num = sum(nums)
        if sum_num % 2 != 0:
            return False
        mid_sum = sum_num // 2
        mid_set = set()
        for i in nums:
            mid = mid_set.copy()
            mid_set.add(i)
            for num in mid:
                mid_num = num + i
                if mid_num < mid_sum:
                    mid_set.add(mid_num)
                elif mid_num == mid_sum:
                    return True
        if mid_sum in mid_set:
            return True
        return False


a = Solution()
print(a.canPartition([1, 5, 11, 5]))
print(a.canPartition([1, 1]))
